#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
/**************************** 随机整数类 ***************************/
/*
1. RI
2. RIL
3. RILU
4. ORIL
*/

// RandomInt
// 生成一个介于两个整数值之间的整数（包括边界值）
bool hasInit = 0;
ll RI(ll minNum, ll maxNum) {
	if(!hasInit)	srand(time(NULL));
	hasInit = 1;
	ll b = minNum+rand()%(maxNum-minNum+1);
	return b;
}

// RandomIntList
// 生成n个元素值在minNum~maxNum的数，数字可以重复，以空格分隔
vector<ll> RIL(ll n, ll minNum, ll maxNum) { 
    vector<ll> result;
	for(ll i=1; i<=n; i++)	result.push_back(RI(minNum, maxNum));
	return result;
}

// RandomIntListUnique
vector<ll> RILU(ll n, ll min_val, ll max_val) {
    vector<ll> result;
    
    // 检查参数是否有效
    if (n <= 0 || min_val > max_val) {
        cout << "Error: 参数有误，请检查！" << endl;
        return result;
    }
    
    // 计算可能的值范围
    ll range = max_val - min_val + 1;
    
    // 如果请求的数量大于可能的值范围，则调整n
    if (n > range) {
        cout << "Error: 参数有误，请检查！" << endl;
        return result;
    }
	
	list<ll> l1;
	// cout << "s1=" << l1.size() << endl;
	for(ll i=min_val; i<=max_val; i++) {
		l1.push_back(i);
	}
	// cout << "s2=" << l1.size() << endl;

	ll c, t1, t2;
	list<ll>::iterator it;
	for(ll i=0; i<n; i++) {
		c = l1.size();
		it = l1.begin();
		t1 = RI(0, c-1);
		advance(it, t1);
		result.push_back(*it);
		l1.erase(it);
		// cout << i << " ";
	}
	// cout << "s3=" << l1.size() << endl;

    return result;
}

// Output Int 输出整数
void OI(ll n, char seprator='\0') {
	if(seprator=='\0')	printf("%lld", n);
	else	printf("%lld%c", n, seprator);
}

// Output Random Int
ll ORI(ll minNum, ll maxNum, char seprator='\0') {
	ll n = RI(minNum, maxNum);
	OI(n, seprator);
	return n;
}

// OutputVectorInt
void OVI(vector<ll> v, char seprator='\0', char endTag='\0') {
	for(vector<ll>::iterator it=v.begin(); it!=v.end(); it++) {
		printf("%d", *it);
		if(seprator!='\0')	printf("%c", seprator);
	}
	if(endTag!='\0')	printf("%c", endTag);
}

// Output Random ll List
// 生成n个元素值在minNum~maxNum的数，数字可以重复，以空格分隔
vector<ll> ORIL(ll n, ll minNum, ll maxNum, char seprator='\0', char endTag='\0') {
	vector<ll> v1 = RIL(n, minNum, maxNum);
	OVI(v1, seprator, endTag);
	return v1;
}

// Output Random ll List Unique
// 生成n个数据范围在[l,r]之间的数列，数字不能重复，以空格分隔
// TODO 当前这个方案在数字范围很大时会

vector<ll> ORILU(ll n, ll l, ll r, char seprator='\0', char endTag='\0') {
    vector<ll> v = RILU(n, l, r);
	OVI(v, seprator, endTag);
	return v;
}

// Output Random N Random ll List
// 输出随机个数n，同时输出n个元素值在minNum~maxNum的数，数字可以重复，以空格分隔
vector<ll> ORNRIL(ll minN, ll maxN, ll minNum, ll maxNum) {
	ll n = RI(minN, maxN);
	cout << n << endl;
	return ORIL(n, minNum, maxNum);
}

// Output Random N Random ll List Unique
// 输出随机个数n，同时输出n个元素值在minNum~maxNum的数，数字不可以重复，以空格分隔
vector<ll> ORNRILU(ll minN, ll maxN, ll minNum, ll maxNum) {
	ll n = RI(minN, maxN);
	cout << n << endl;
	return ORILU(n, minNum, maxNum);
}
/**************************** 随机整数类 ***************************/


/**************************** 随机浮点数类 ***************************/

void OF(double f, ll accuracy=2, char seprator='\0') {
	cout << fixed << setprecision(accuracy) << f;
	if(seprator!='\0')	cout << seprator;
}

// 生成一个浮点数
double RF(ll minNum, ll maxNum, ll accuracy=2) {
	if(!hasInit)	srand(time(NULL));
	hasInit = 1;

	double b = (minNum+rand()%(maxNum-minNum+1))*1.0;
	double a = 0.1;
	while(accuracy--) {
		b += RI(0, 9)*a;//accuracy==0?1:0
		a *= 0.1;
	}
	return b;
}

// RandomFloatList
// 生成n个元素值在minNum~maxNum的浮点数，数字可以重复，以空格分隔
vector<double> RFL(ll n, ll minNum, ll maxNum, ll accuracy=2) { 
    vector<double> result;
	for(ll i=1; i<=n; i++)	result.push_back(RF(minNum, maxNum, accuracy));
	return result;
}

// TODO： RandomFloatListUnique
vector<double> RFLU(ll n, ll min_val, ll max_val, ll accuracy=2) {
    vector<double> result;
    
    // 检查参数是否有效
    if (n <= 0 || min_val > max_val) {
        cout << "Error: 参数有误，请检查！" << endl;
        return result;
    }

	set<double> s1;
	double r;
	while(n--) {
//		do {
//			r = RF(min_val, max_val, accuracy);
//		} while(s1.find(r)); 
//		s1.push_back(r);
//		result.push_back(r);
	}

    return result;
}

// OutputVectorFloat
void OVF(vector<double> v, ll accuracy=2, char seprator='\0', char endTag='\0') {
	for(vector<double>::iterator it=v.begin(); it!=v.end(); it++) {
		OF(*it, accuracy, seprator);
		// printf("%.2lf", *it);
	}
	if(endTag!='\0')	printf("%c", endTag);
}

// Output Random Float
double ORF(ll minNum, ll maxNum, ll accuracy=2, char seprator='\0', char endTag='\0') {
	double n = RF(minNum, maxNum, accuracy);
	OF(n, accuracy, seprator);
	if(endTag!='\0')	printf("%c", endTag);
	return n;
}

// Output Random Float List
vector<double> ORFL(ll n, ll minNum, ll maxNum, ll accuracy=2, char seprator='\0', char endTag='\0') {
	vector<double> v1 = RFL(n, minNum, maxNum, accuracy);
	OVF(v1, accuracy, seprator, endTag);
	return v1;
}

/**************************** 随机浮点数类 ***************************/

/**************************** 随机字符类 ***************************/

// 返回介于c1字符至c2字符之间的随机字符
char RC(char c1, char c2) {
	char c = c1 + RI(0, c2 - c1);
	return c;
}

// 跟RIL相同功能，区别在于可以没有分隔字符，字符可重复
vector<char> RCL(ll n, char c1, char c2) {
	vector<char> v;
	for(ll i=1; i<=n; i++)	v.push_back(RC(c1, c2));
	return v;
}

// 跟RILU相同功能，区别在于可以没有分隔字符，字符不可重复
vector<char> RCLU(ll n, char c1, char c2) {
	vector<char> result;
	list<char> l1;
	for(char i=c1; i<=c2; i++)	l1.push_back(i);

	ll c, t1, t2;
	list<char>::iterator it;
	for(ll i=0; i<n; i++) {
		c = l1.size();
		it = l1.begin();
		t1 = RI(0, c-1);
		advance(it, t1);
		result.push_back(*it);
		l1.erase(it);
	}

	return result;
}

// Random Char-Number 输出数字
char RCN() {
	return RC('0', '9');
}

// Random Char-Letter-Big 输出大写字母
char RCLB() {
	return RC('A', 'Z');
}

// Random Char-Letter-Small 输出大写字母
char RCLS() {
	return RC('a', 'z');
}

// Random Char-Sign 输出不是字母和数字的特殊字符
char RCS() {
	return RC('!', '/');
}

// Random Char-EmptySpace 输出空格
char RCE() {
	return ' ';
}

void OC(char c, char seprator='\0') {
	if(seprator=='\0')	printf("%c", c);
	else	printf("%c%c", c, seprator);
}

char ORC(char c1, char c2, char seprator='\0') {
	char c = RC(c1, c2);
	OC(c, seprator);
	return c;
}

// OutputVectorChar
void OVC(vector<char> v, char seprator='\0', char endTag='\0') {
	for(vector<char>::iterator it=v.begin(); it!=v.end(); it++)
		OC(*it, seprator);
	if(endTag!='\0')	printf("%c", endTag);
}

// 输出n个介于c1字符至c2字符之间的随机字符，字符可重复
vector<char> ORCL(ll n, char c1, char c2, char seprator='\0', char endTag='\0') {
	vector<char> v = RCL(n, c1, c2);
	OVC(v, seprator, endTag);
	return v;
}

// 输出n个介于c1字符至c2字符之间的随机字符，字符不可重复
vector<char> ORCLU(ll n, char c1, char c2, char seprator='\0', char endTag='\0') {
	vector<char> v = RCLU(n, c1, c2);
	OVC(v, seprator, endTag);
	return v;
}

// Random Char-5 List 输出四类字符中任意的1个字符，百分点个数（数字：大写：小写：符号：空格）
vector<char> RC5L(int n, int pn=25, int plb=25, int pls=25, int ps=20, int pe = 5) {
	vector<char> v;
	int k;
	char c;

	if(pn+plb+pls+ps+pe!=100) {
		cout << "五类比例数字的和要等于100";
		return v;
	}

	while(n--) {
		k = RI(1, 100);

		if(pn && k<=pn)	c = RCN();
		else if(plb && k<=pn+plb)	c = RCLB();
		else if(pls && k<=pn+plb+pls)	c = RCLS();
		else if(ps && k<=pn+plb+pls+ps)	c = RCS();
		else	c = RCE();
		
		v.push_back(c);
	}
	return v;
}

// Output Random Char-5 List 输出四类字符中任意的1个字符，百分点个数（数字：大写：小写：符号：空格）
vector<char> ORC5L(int n, int pn=25, int plb=25, int pls=25, int ps=20, int pe = 5, char seprator='\0', char endTag='\0') {
	vector<char> v = RC5L(n, pn, plb, pls, ps, pe);
	OVC(v, seprator, endTag);
	return v;
}

void OName(ll len=5) {
	char c1 = 'A' + RI(0, 25);
	cout << c1;
	ORCLU(RI(2, len-1), 'a', 'z', '\0', ' ');
}

/**************************** 随机字符类 ***************************/

/**************************** 随机字符串类 ***************************/

string RS(int n, char c1, char c2) {
	string s;
	vector <char> v = RCL(n, c1, c2);
	for(vector <char>::iterator it=v.begin(); it!=v.end(); it++) {
		s += *it;
	}
	return s;
}

/**************************** 随机字符串类 ***************************/

/*****  其他  *****/

// Connect String Number 将数字插入到两个字符串中间后返回字符串
string csn(const string& str1, ll num, const string& str2) {
    // 使用stringstream进行字符串拼接
    stringstream ss;
    ss << str1 << num << str2;
    return ss.str();// 如果要返回const char*的话就要再调用.c_str()方法
}

// Connect String Number char* 将数字插入到两个字符串中间后返回const char*
const char* csn_c(const string& str1, ll num, const string& str2) {
    return csn(str1, num, str2).c_str();
}

char JinZhi(int n) {
	if(n<10)	return '0' + n;
	else return 'A' + (n-10);
}


void empty() {
	cout << " ";
}
void line() {
	cout << endl;
}
/*****  其他  *****/